from soap_types import *

def map_author(author):
    a = AuthorSoap()
    a.id = author.id
    a.name = author.name
    a.surname = author.surname
    a.books = [book.id for book in author.books]
    return a

def map_book(book):
    b = BookSoap()
    b.id = book.id
    b.title = book.title
    b.description = book.description
    b.authors = [author.id for author in book.authors]
    b.genres = [genre.id for genre in book.genres]
    b.products = [product.id for product in book.products]
    return b
    
def map_bookshop(bookshop):
    b = BookshopSoap()
    b.id = bookshop.id
    b.company_name = bookshop.company_name
    b.vat = bookshop.vat
    b.iban = bookshop.iban
    b.orders = [order.id for order in bookshop.orders]
    return b

def map_user(user):
    u = UserSoap()
    u.id = user.id
    u.username = user.username
    u.email = user.email
    u.active = user.active
    u.subject = user.subject.id
    u.type = user.subject.row_type
    return u

def map_product(product):
    p = ProductSoap()
    p.id = product.id
    p.name = product.name
    p.description = product.description
    p.edition = product.edition.id
    p.price = product.price
    p.quantity = product.quantity
    p.discount = product.discount
    p.books = [book.id for book in product.books]
    return p

def map_order(order):
    o = OrderSoap()
    o.id = order.id
    o.bookshop = map_bookshop(order.bookshop)
    o.date = order.date
    o.status = order.status
    o.total_amount = order.total_amount
    return o
    
def map_orderdetail(orderdetail):
    o = OrderDetailSoap()
    o.order = orderdetail.order.id
    o.product = map_product(product)
    return o

def map_genre(genre):
    g = GenreSoap()
    g.id = genre.id
    g.name = genre.name
    g.description = genre.description
    return g
